﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DayBook.aspx.cs" Inherits="Main_Reports_Accounts_AccountBooks_DayBook" %>

<%@ Register Src="~/User Controls/PageHeading.ascx" TagName="Heading" TagPrefix="acc" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../../../../Styles/accounts.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="../../../JavaScript/jquery-1.3.2.min.js"></script>

    <script type="text/javascript">
        function expandDetailsInGrid(imgId, grdId) {
            var imgelem = document.getElementById(imgId);
            var rowdetelem = document.getElementById(grdId);
            if (imgelem.alt == "plus") {
                imgelem.src = "../../../../Images/minus.png";
                imgelem.alt = "minus";

                rowdetelem.style.display = "block";

            }
            else {
                imgelem.src = "../../../../Images/plus.png";
                imgelem.alt = "plus";
                rowdetelem.style.display = "none";
            }
            return false;
        }

        function Validation() {
            var flag = true;
            var txtFromdate = document.getElementById("txtFromDate").id;
            var txtTodate = document.getElementById("txtToDate").id;

            if (document.getElementById("txtFromDate").value == '') {
                alert('Specify From date');
                flag = false;
            }
            else if (document.getElementById("txtToDate").value == '') {
                alert('Specify To date');
                flag = false;
            }
            else {
                if (isDate(txtFromdate) && isDate(txtTodate)) {
                    var dateArray = new Array();
                    dateArray = document.getElementById("txtFromDate").value.split("/");
                    var day1 = dateArray[0];
                    var month1 = dateArray[1];
                    var year1 = dateArray[2];
                    dateArray = document.getElementById("txtToDate").value.split("/");
                    var day2 = dateArray[0];
                    var month2 = dateArray[2];
                    var year2 = dateArray[2];

                    if (day1.length < 2) {
                        day1 = '0' + day1;
                    }
                    if (month1.length < 2) {
                        month1 = '0' + month1;
                    }
                    if (day2.length < 2) {
                        day2 = '0' + day2;
                    }
                    if (month2.length < 2) {
                        month2 = '0' + month2;
                    }
                    var date1 = new Date(year1, month1 - 1, day1);
                    var date2 = new Date(year2, month2 - 1, day2);
                    if (date1 > date2) {
                        alert('Date Could Not be less than From Date');
                        document.getElementById(txtFromdate).focus();
                        flag = false;

                    }
                }
                else {
                    flag = false;
                }
            }
            return flag;
        }
        function isDate(txtDateId) {
            // date length should be 10 characters - no more, no less            
            var Ctrl = document.getElementById(txtDateId);
            var txtDate = Ctrl.value;
            var flag = true;

            // extract day, month and year from the txtDate string
            // expected format is dd/mm/yyyy
            var day = '';
            var month = '';
            var year = '';
            var dateArray = new Array();
            var count = 0;
            for (var j = 0; j < txtDate.length; j++) {
                var chara = txtDate.charAt(j);
                if (chara == '/') {
                    count += 1;
                }
            }
            if (count != 2) {
                alert('Invalid date !');
                return false;
            }
            dateArray = txtDate.split("/");


            day = dateArray[0];
            month = dateArray[1];
            year = dateArray[2];


            if (year.length != 4) {
                alert('Invalid date !');
                return false;
            }
            var finYear = document.getElementById("hidFinyear").value;
            if (month >= 4 && year != parseInt(finYear)) {
                alert('Date Should be between 01/04/' + finYear + ' and 31/03/' + (parseInt(finYear) + 1));
                return false;
            }
            else if (month < 4 && year != (parseInt(finYear) + 1)) {
                alert('Date Should be between 01/04/' + finYear + ' and 31/03/' + (parseInt(finYear) + 1));
                return false;
            }



            if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
                if (day > 31) {
                    alert('Date Should not be Greater than 31');
                    Ctrl.focus();
                    flag = false;
                }
            }
            //for have only 30 day
            else if (month == 4 || month == 6 || month == 9 || month == 11) {
                if (day > 30) {
                    alert('Date Should not be Greater than 30');
                    Ctrl.focus();
                    flag = false;
                }
            }
            //for Febuary 
            else if (month == 2) {
                var leap = year % 4;
                if (leap == 0) {
                    if (day > 29) {
                        alert('february have only 29 days');
                        Ctrl.focus();
                        flag = false;
                    }
                }
                else {
                    if (day > 28) {
                        alert('february have only 28 days');
                        Ctrl.focus();
                        flag = false;
                    }
                }
            }
            else if (month > 12) {
                alert('Invalid Date');
                Ctrl.focus();
                flag = false;
            }
            // otherwise return true
            return flag;
        }
        function printpartofpage() {
            var printWindow = window.open('DayBookPrintReportt.aspx', '', 'left=50,top=50,width=800,height=500');

            return false;

        }      
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <ajax:ToolkitScriptManager ID="tc" runat="server">
    </ajax:ToolkitScriptManager>
    <asp:HiddenField ID="hidFinyear" runat="server" />
    <div class="divmain">
        <acc:Heading ID="pagehead" runat="server" HeadingText="Day Book" />
    </div>
    <table style="width: 96%;">
        <tr>
            <td>
                <asp:LinkButton ID="lnkbtn" runat="server" Text="Change Dare"></asp:LinkButton>&nbsp;
                <asp:HyperLink ID="hpr" runat="server" Text="Print" NavigateUrl="#" OnClick="return printpartofpage();"></asp:HyperLink>
            </td>
        </tr>
    </table>
    <div id="divDetail" style="width: 100%;">
        <table style="width: 96%; margin-left: 2%;">
            <tr align="center">
                <td>
                    <asp:Label ID="lblcompname" runat="server" Font-Bold="true" Font-Size="Small"></asp:Label>
                </td>
            </tr>
            <tr align="center">
                <td>
                    <asp:Label ID="lblheading" runat="server"></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Panel ID="panel1" Visible="false" runat="server" BorderWidth="1px" Width="98%"
                        Height="20px">
                        <center>
                            <asp:Label ID="lblempty1" Text="Records Not Found!!!!" runat="server" Font-Bold="true"
                                Font-Size="Small" ForeColor="Red"></asp:Label></center>
                    </asp:Panel>
                    <asp:DataList ID="Datalist1" OnItemDataBound=" Datalist_itembound" runat="server"
                        Width="96%" ItemStyle-BorderStyle="Solid" ItemStyle-BorderWidth="1px" ItemStyle-BorderColor="#818181"
                        SelectedItemStyle-VerticalAlign="Top">
                        <ItemStyle BorderColor="#818181" BorderWidth="1px" BorderStyle="Solid"></ItemStyle>
                        <SelectedItemStyle VerticalAlign="Top"></SelectedItemStyle>
                        <ItemTemplate>
                            <asp:ImageButton ID="imgShow" runat="server" AlternateText="minus" ImageUrl="~/Images/minus.png" />
                            <asp:Label ID="lblDate" runat="server" Text='<%# string.Format("{0:dd-MMM-yyyy}",Eval("TransactionDate"))%>'></asp:Label>
                            <asp:GridView ID="grdDisplay" OnRowDataBound="row_DataBound" CssClass="gridview"
                                Width="100%" runat="server" AutoGenerateColumns="false">
                                <Columns>
                                    <asp:BoundField ItemStyle-Width="10%" HeaderText="Date" DataField="TransactionDate"
                                        DataFormatString="{0:dd-MMM-yyyy}" />
                                    <asp:BoundField ItemStyle-Width="10%" HeaderText="Type" DataField="Name" />
                                    <asp:BoundField ItemStyle-Width="10%" HeaderText="Voucher No." DataField="TransactionNumber" />
                                    <asp:BoundField HeaderText="Ref No." ItemStyle-Width="10%" DataField="ReferenceNumber" />
                                    <asp:BoundField HeaderText="Particulars" ItemStyle-Width="10%" DataField="Particulars" />
                                    <asp:BoundField HeaderText="Debit" ItemStyle-Width="10%" DataField="Debit" ItemStyle-HorizontalAlign="Right" />
                                    <asp:BoundField HeaderText="Credit" ItemStyle-Width="10%" DataField="Credit" ItemStyle-HorizontalAlign="Right" />
                                </Columns>
                            </asp:GridView>
                        </ItemTemplate>
                        <%-- <%--<FooterTemplate>
<asp:Label ID="lblEmpty" runat="server">

</asp:Label>
</FooterTemplate>--%>
                    </asp:DataList>
                </td>
            </tr>
        </table>
    </div>
    <asp:Panel ID="panel" CssClass="modalPopup" runat="server" Width="250px" Height="110px">
        <table width="90%" style="margin-left: 7%; margin-top: 20px;">
            <tr>
                <td>
                    From:
                </td>
                <td>
                    <asp:TextBox ID="txtFromDate" runat="server" Width="100px" CssClass="input"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    To :
                </td>
                <td>
                    <asp:TextBox ID="txtToDate" runat="server" Width="100px" CssClass="input"></asp:TextBox>
                </td>
            </tr>
            <tr align="center">
                <td colspan="2">
                    <asp:Button ID="btnShow" Text="Show" OnClientClick="return Validation();" runat="server"
                        CssClass="button" OnClick="btnShow_Click" />
                    <asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="button" />
                </td>
            </tr>
        </table>
    </asp:Panel>
    <ajax:ModalPopupExtender ID="modalpopup" BackgroundCssClass="modalBackground" runat="server"
        PopupControlID="panel" TargetControlID="lnkbtn" CancelControlID="btnCancel">
    </ajax:ModalPopupExtender>
    </form>
</body>
</html>
